/* QtLua -- Lua bindings for Qt
   Copyright (C) 2011, Jarek Pelczar

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301 USA

*/

#ifndef QLUASCRIPTDEBUGGER_P_P_H
#define QLUASCRIPTDEBUGGER_P_P_H

#include "qluascriptdebugger_p.h"
#include <QEventLoop>

class QLuaDebuggerAgent;
class QLuaScriptsDebuggerScriptModel;
class QLuaScriptValue;
class QLuaScriptDebuggerScriptWindowInterface;
class QLuaScriptDebuggerWidgetFactoryInterface;
class QLuaScriptBreakpointModel;
class QLuaScriptBreakpointsWidgetInterface;
class QLuaScriptDebuggerStackModel;
class QLuaScriptDebuggerStackWidgetInterface;
class QLuaScriptDebuggerLocalsWidgetInterface;
class QLuaScriptDebuggerLocalsModel;
class QLuaScriptDebuggerScriptEditorInterface;
class QLuaScriptDebuggerCodeWidgetInterface;

class QLuaScriptDebuggerPrivate
{
public:
    QLuaScriptDebuggerPrivate();
    ~QLuaScriptDebuggerPrivate();

    QLuaScriptDebugger * q;
    QLuaDebuggerAgent * m_debugAgent;
    QLuaScriptsDebuggerScriptModel * m_scriptModel;
    QLuaScriptDebuggerWidgetFactoryInterface * m_widgetFactory;
    QLuaScriptBreakpointModel * m_breakpointModel;
    QLuaScriptDebuggerStackModel * m_stackModel;
    QLuaScriptDebuggerLocalsModel * m_localsModel;

    QLuaScriptDebuggerScriptWindowInterface * m_scriptWindow;    
    QLuaScriptBreakpointsWidgetInterface * m_breakpointWindow;
    QLuaScriptDebuggerStackWidgetInterface * m_stackWindow;
    QLuaScriptDebuggerLocalsWidgetInterface * m_localsWindow;
    QLuaScriptDebuggerCodeWidgetInterface * m_editorWindow;

    QAction * m_interruptAction;
    QAction * m_continueAction;
    QAction * m_stepIntoAction;
    QAction * m_stepOverAction;
    QAction * m_stepOutAction;
    QAction * m_runToCursorAction;
    QAction * m_runToNewScriptAction;

    // Debugger stop/continue state
    enum ActionDecision {
        NoDebugAction,
        FirstChanceBreakAction,
        StepIntoAction,
        StepOutAction,
        StepOverAction,
        RunToNewScriptAction
    };

    QEventLoop * m_currentLoop;
    ActionDecision m_actionDecision;

    void _p_contextPop();
    void _p_contextPush();
    void _p_exceptionCatch(qint64, const QLuaScriptValue&);
    void _p_exceptionThrow(qint64, const QLuaScriptValue&, bool);
    void _p_functionEntry(qint64);
    void _p_functionExit(qint64, const QLuaScriptValue&);
    void _p_positionChange(qint64, int, int);
    void _p_scriptLoad(qint64, QString, QString, int);
    void _p_scriptUnload(qint64);
    void _p_currentScriptChanged(qint64);
    void _p_continue();
    void _p_interrupt();
    void _p_stepInto();
    void _p_stepOver();
    void _p_runToCursor();
    void _p_runToNewScript();
    void _p_stepOut();

    void breakIntoDebugger(qint64 sid);

    QAction * interruptAction(QObject * actionParent);
    QAction * continuteAction(QObject * actionParent);
    QAction * stepIntoAction(QObject * actionParent);
    QAction * stepOverAction(QObject * actionParent);
    QAction * stepOutAction(QObject * actionParent);
    QAction * runToCursorAction(QObject * actionParent);
    QAction * runToNewScriptAction(QObject * actionParent);
};

#endif // QLUASCRIPTDEBUGGER_P_P_H
